<#include "/common/include.html"/>
<@pageTheme mark="${config.optimize()?string('true', 'false')}">
<@header title="代码生成列表"/>
<@search fromId="gen-form">
	<div class="select-list">
		<ul>
			<li>
				表名称：
				<select name="tableName" class="form-control">
					<option value="">所有</option>
					<#list genTables>
						<#items as d>
								<option value="${d.tableName}">${d.tableName}</option>
						</#items>
					</#list>
				</select>
			</li>
			<li>
				表描述：
				<select name="tableComment" class="form-control">
					<option value="">所有</option>
					<#list genTables>
						<#items as d>
							<option value="${d.tableComment}">${d.tableComment}</option>
						</#items>
					</#list>
				</select>
			</li>
			<li class="select-time">
				<label>表时间： </label>
				<input type="text" class="time-input" id="startTime" placeholder="开始时间" name="startTime"/>
				<span>-</span>
				<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
			</li>
			<li>
				<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
				<a class="btn btn-warning btn-rounded btn-sm" onclick="opt.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
			</li>
		</ul>
	</div>
</@search>
<@table tableId="bootstrap-table">
	<@shiro.hasPermission name="tool:gen:code">
		<a class="btn btn-success multiple disabled" onclick="javascript:batchGenCode()">
			<i class="fa fa-download"></i> 生成
		</a>
	</@shiro.hasPermission>
		<a class="btn btn-info" onclick="selectDb()">
			<i class="fa fa-upload"></i> 导入
		</a>
	<@shiro.hasPermission name="tool:gen:edit">
		<a class="btn btn-primary single disabled" onclick="opt.operate.editTab()">
			<i class="fa fa-edit"></i> 修改
		</a>
	</@shiro.hasPermission>
	<@shiro.hasPermission name="tool:gen:del">
		<a class="btn btn-danger multiple disabled" onclick="opt.operate.delAll()">
			<i class="fa fa-remove"></i> 删除
		</a>
	</@shiro.hasPermission>
</@table>
<@footer>
	<script>
		var prefix = baseURL + "tool/gen";
		var editFlag = "${permission.hasPermi('tool:gen:edit')}";
		var delFlag = "${permission.hasPermi('tool:gen:del')}";
		var previewFlag =  "${permission.hasPermi('tool:gen:preview')}";
		var codeFlag = "${permission.hasPermi('tool:gen:code')}";
	
		$(function() {
		    var options = {
		        url: prefix + "/list",
				editUrl: prefix + "/edit/{id}",
		        delUrl: prefix + "/del",
		        sortName: "createTime",
		        sortOrder: "desc",
		        showExport: true,
		        modalName: "生成配置",
		        columns: [{
		            checkbox: true
		        },
		        {
		            field: 'tableId',
		            title: '<@ctx.i18n text = "编号"/>',
		            visible: false
		        },
		        {
                    title: "<@ctx.i18n text = "序号"/>",
                    formatter: function (value, row, index) {
                 	    return $.table.serialNumber(index);
                    }
                },
		        {
		            field: 'tableName',
		            title: '<@ctx.i18n text = "表名"/>',
		            sortable: true
		        },
		        {
		            field: 'tableComment',
		            title: '<@ctx.i18n text = "表描述"/>'
		        },
				{
					field: 'functionAuthor',
					title: '<@ctx.i18n text = "作者"/>'
				},
		        {
		            field: 'className',
		            title: '<@ctx.i18n text = "实体类名称"/>',
		            sortable: true
		        },
		        {
		            field: 'createTime',
		            title: "<@ctx.i18n text = "创建时间"/>",
		            sortable: true
		        },
		        {
		            field: 'updateTime',
		            title: "<@ctx.i18n text = "更新时间"/>",
		            sortable: true
		        },
		        {
		            title:"<@ctx.i18n text = "操作"/>",
		            align: 'left',
					width: 120,
					class:'action',
		            formatter: function(value, row, index) {
		                /*var actions = [];
		                actions.push('<a class="btn btn-info btn-xs ' + previewFlag + '" href="javascript:void(0)" onclick="preview(\'' + row.tableId + '\')"><i class="fa fa-search"></i>预览</a> ');
		                actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="opt.operate.editTab(\'' + row.tableId + '\')"><i class="fa fa-edit"></i><@ctx.i18n text = "编辑"/></a> ');
		                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="opt.operate.del(\'' + row.tableId + '\')"><i class="fa fa-remove"></i>删除</a> ');
		                actions.push('<a class="btn btn-primary btn-xs ' + codeFlag + '" href="javascript:void(0)" onclick="genCode(\'' + row.tableName + '\')"><i class="fa fa-bug"></i>生成代码</a> ');
		                return actions.join('');*/

						var actions = [];
						actions.push('<a class="' + previewFlag + '" href="javascript:void(0)" title="<@ctx.i18n text = "预览"/>" onclick="preview(\'' + row.tableId + '\')"><i class="fa fa-search"></i></a> ');
						actions.push('<a class="' + editFlag + '" href="javascript:void(0)" title="<@ctx.i18n text = "编辑"/>" onclick="opt.operate.editTab(\'' + row.tableId + '\')"><i class="fa fa-edit"></i></a> ');
						actions.push('<a class="' + delFlag + '" href="javascript:void(0)" title="<@ctx.i18n text = "删除"/>" onclick="opt.operate.del(\'' + row.tableId + '\')"><i class="fa fa-trash-o"></i></a> ');
						var info = "<a  class='btn btn-default btn-xs "+codeFlag+"' onclick=codeDownload(\'" + row.tableName + "\');><i class='fa icon-cloud-download'></i> <@ctx.i18n text = "下载代码"/></a>&nbsp;";
						info += "<a  class='btn btn-default btn-xs "+codeFlag+"' onclick=genCode(\'"+row.tableName+"\',\'" + row.tableId + "\',\'"+row.isCover+"\');><i class='fa fa-bug'></i> <@ctx.i18n text = "生成代码"/></a>&nbsp;";
						actions.push('<a tabindex="0"  role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="'+info+'"><i class="fa fa-chevron-circle-right" title="<@ctx.i18n text = "更多操作"/>"></i></a>');
						return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);
		});
		
		/*预览代码*/
		function preview(tableId) {
			var options = {
				url: prefix + "/preview/" + tableId,
				title:'预览代码',
                btn:['<i class="fa fa-close"></i> '+$.i18n.prop("取消")],
			};
			opt.modal.openMainWin(options);
		}
	
		/*生成代码*/
		function codeDownload(tableName) {
		    opt.modal.confirm("确定要下载" + tableName + "生成表代码吗?", function() {
		    	location.href = prefix + "/download/" + tableName;
				opt.modal.msg('执行成功,正在生成代码请稍后…');
		    })
		}

		function genCode(tableName,tableId,isCover){
			var c = "确定要生成表["+tableName+"]代码";
			if(isCover === "Y"){
				c+=",<span style='color: red;font-weight: bold'>覆盖替换原有文件</span>"
			}
			opt.modal.confirm(c+"吗?", function() {
				var data = {'tableId':tableId};
				var url = prefix + "/genCode";
				opt.operate.post(url,data);
			})
		}
	
		/*批量生成代码*/
		function batchGenCode() {
		    var rows = $.table.selectColumns("tableName");
		    if (rows.length == 0) {
		        opt.modal.alertWarning("请选择要生成的数据");
		        return;
		    }
		    opt.modal.confirm("确认要生成选中的" + rows.length + "条数据吗?", function() {
		    	location.href = prefix + "/batchGenCode?tables=" + rows;
				opt.modal.msg('执行成功,正在生成代码请稍后…');
		    });
		}
		
		/*导入表结构*/
		function importTable(id) {
			var importTableUrl = prefix + "/importTable/" +id;
			opt.modal.open("导入表结构", importTableUrl);
		}

		/* 用户管理-重置密码 */
		function selectDb() {
			var options = {
				title: "选择数据库",
				width: "800",
				height: "240",
				url: prefix + '/selectDb',
				callBack: DeptDoSubmit
			};
			opt.modal.openOptions(options);
		}
		
		function DeptDoSubmit(index, layero) {
			var body = layer.getChildFrame('body', index);
			importTable(body.find('#dbType').val());
			layer.close(index);
		}
	</script>
</@footer>
</@pageTheme>